package com.ccp.dev.qbdms.service;

import com.ccp.dev.core.basic.base.BaseService;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.util.BeanUtils;
import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.extend.model.ExtendSysFile;
import com.ccp.dev.form.service.impl.ScriptImpl;
import com.ccp.dev.qbdms.dao.WFadongjiDao;
import com.ccp.dev.qbdms.model.WFadongji;
import com.ccp.dev.qbdms.util.BaseUtil;
import com.ccp.dev.qbdms.util.ReadAttachmentUtil;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 发动机试车 信息操作服务类
 *
 * @author sun
 * @date 2020-06-08 13:45:02
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class WFadongjiService extends BaseService<WFadongji> {

    @Resource
    private WFadongjiDao dao;
    @Resource
    private ScriptImpl script;

    /**
     * 查询全部,导出用
     * @param queryFilter
     * @return
     */
    public List<WFadongji> queryAll(QueryFilter queryFilter){
        return dao.queryAll(queryFilter);
    }


    /**
     * 查询上报流程的业务数据
     *
     * @param dataId
     * @param tableName
     * @return
     */
    public List<WFadongji> reportList(String dataId, String tableName) {
        return dao.reportList(dataId, tableName);
    }


    /**
     * 用于上报获取数据
     * @param dataId
     * @return
     */
    public WFadongji getParentAndChilden(String dataId) {
        return dao.getById(dataId);
    }

    /**
     * 接收上报来的数据
     * @param data
     */
    public void saveAll(List<WFadongji> data,List<ExtendSysFile> extendSysFileList){
        ReadAttachmentUtil.getEntityData(data,extendSysFileList);
        for (WFadongji fadongji : data) {
            // 如果上报数据中hospital为空,认为是三级上报来的,如果不为空,则认为是二级上报来的
            if (StringUtil.isEmpty(fadongji.getFilldeptHospitalId())) {
                fadongji.setBelongdeptname(BaseUtil.getCurrentTenOrgCodePath(fadongji.getFilldeptid()));
            }
            else{
                fadongji.setBelongdeptname(BaseUtil.getCurrentTenOrgCodePath(fadongji.getFilldeptHospitalId()));
            }
            WFadongji temp = dao.getById(fadongji.getId());
            if (BeanUtils.isNotEmpty(temp)) {
                update(fadongji);
            }
            else{
                add(fadongji);
            }
        }
    }


}
